package com.blank.web.servlet;

import com.blank.web.bean.Student;
import com.blank.web.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "showStuInfoServlet",urlPatterns = "/showStuInfo")
public class showStuInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、查询所有学生信息
        StudentService studentService = new StudentService();
        List<Student> studentList = studentService.findAll();
        //2、将数据存储到request中
        request.setAttribute("list",studentList);
        System.out.println(studentList);
        //3、进行页面的跳转
        request.getRequestDispatcher("showStuInfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
